package com.kinghood.productcenter.controller.base;

import com.kinghood.infrastructure.api.authority.SysLogModuleEnum;
import com.kinghood.infrastructure.aspect.OperatorLog;
import com.kinghood.infrastructure.model.KingHoodResponseVO;
import com.kinghood.infrastructure.model.dto.StatusReqDTO;
import com.kinghood.productcenter.common.model.dto.base.LabelReqDTO;
import com.kinghood.productcenter.common.model.dto.base.ListLabelQueryDTO;
import com.kinghood.productcenter.manager.impl.BaseLabelManager;
import com.kinghood.productcenter.service.base.IBaseLabelService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 * 基础选项-标签表 前端控制器
 * </p>
 *
 * @author KingHood
 * @since 2023-12-20
 */
@RestController
@RequestMapping("/baseLabel")
public class BaseLabelController {
    @Resource
    private IBaseLabelService labelService;
    @Resource
    private BaseLabelManager labelManager;

    /**
     * 列表
     *
     * @author jp
     * @date 2023/12/20
     */
    @PostMapping("/listLabel")
    public KingHoodResponseVO listLabel(@RequestBody ListLabelQueryDTO param) {
        return KingHoodResponseVO.success(labelService.listLabel(param));
    }

    /**
     * 获取所有标签
     *
     * @author jp
     * @date 2024/01/02
     */
    @PostMapping("/getAllLabel")
    public KingHoodResponseVO getAllLabel() {
        return KingHoodResponseVO.success(labelService.getAllLabel());
    }

    /**
     * 新增更新
     *
     * @param param
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_LABEL,content = "标签管理-新增、修改标签")
    @PostMapping("/addOrUpdateLabel")
    public KingHoodResponseVO addOrUpdateLabel(@Valid @RequestBody LabelReqDTO param) {
        labelService.addOrUpdateLabel(param);
        return KingHoodResponseVO.success();
    }

    /**
     * 根据id删除
     *
     * @param id id
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_LABEL,content = "标签管理-删除标签")
    @RequestMapping("/delLabel/{id}")
    public KingHoodResponseVO delLabel(@PathVariable("id") Long id) {
        labelManager.delLabelById(id);
        return KingHoodResponseVO.success();
    }

    /**
     * 根据ID查询详情
     *
     * @param id id
     * @author jp
     * @date 2023/12/21
     */
    @PostMapping("/detailLabel/{id}")
    public KingHoodResponseVO detailLabel(@PathVariable("id") Long id) {
        return KingHoodResponseVO.success(labelService.detailLabel(id));
    }

    /**
     * 更新标签状态
     *
     * @param param 参数
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_LABEL,content = "标签管理-修改状态")
    @PostMapping("/updateLabelStatus")
    public KingHoodResponseVO updateLabelStatus(@Valid @RequestBody StatusReqDTO param) {
        labelService.updateLabelStatus(param);
        return KingHoodResponseVO.success();
    }

    /**
     * 检查标签值是否在使用中
     *
     * @param id id
     * @author jp
     * @date 2023/12/21
     */
    @RequestMapping("/checkLabelItemUsed/{id}")
    public KingHoodResponseVO checkLabelItemUsed(@PathVariable("id") Long id) {
        labelManager.checkLabelItemUsed(id);
        return KingHoodResponseVO.success();
    }

    /**
     * 下载标签
     *
     * @param param 参数
     * @author jp
     * @date 2024/01/04
     */
    @PostMapping("/downloadLabel")
    public void downloadLabel(@RequestBody ListLabelQueryDTO param, HttpServletResponse response) {
        labelService.downloadLabel(param, response);
    }
}
